//
//  HomeHeaderView.m
//  ZJControlsClass
//
//  Created by apple on 2024/10/28.
//

#import "HomeHeaderView.h"
#import "HomeHeaderCareCollectionViewCell.h"

#import "HomeTransactPersonViewController.h"
#import "HomeGoodsListViewController.h"

#import "HomeTransferOrderInfoViewController.h"
#import "ZJMineThroughRecordViewController.h"



@interface HomeHeaderView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic,strong) UICollectionView * collectionView;
@property (nonatomic,strong) NSMutableArray * dataSource;
@property (nonatomic,strong) NSMutableArray * imgArr;


@end


@implementation HomeHeaderView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.dataSource = [NSMutableArray arrayWithObjects:@"办理人员/单位通行证",@"办理车辆通行证",@"办理入场工具货物",@"查询办理进度", nil];
        self.imgArr = [NSMutableArray arrayWithObjects:@"通行证",@"通行证",@"货物",@"进度", nil];
        
        [self addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.equalTo(self);
        }];
        
    }
    return self;
}


#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeHeaderCareCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHeaderCareCollectionViewCell" forIndexPath:indexPath];
    
    cell.titleLabel.text = self.dataSource[indexPath.row];
    cell.img.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",self.imgArr[indexPath.row]]];
    
    
    
    if (indexPath.row == 0) {
        cell.follewView.backgroundColor = COLOR_RGB(235, 241, 253);
        cell.intoBtn.backgroundColor = COLOR_RGB(102, 154, 255);
        
        
    }else if (indexPath.row == 1){
        cell.follewView.backgroundColor = COLOR_RGB(240, 236, 253);
        cell.intoBtn.backgroundColor = COLOR_RGB(155, 123, 251);
        
        
    }else if (indexPath.row == 2){
        cell.follewView.backgroundColor = COLOR_RGB(233, 249, 251);
        cell.intoBtn.backgroundColor = COLOR_RGB(64, 213, 229);
        
        
    }else if (indexPath.row == 3){
        cell.follewView.backgroundColor = COLOR_RGB(236, 248, 241);
        cell.intoBtn.backgroundColor = COLOR_RGB(104, 217, 153);
        
        
    }
    
    
    return cell;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        HomeTransactPersonViewController * vc = [HomeTransactPersonViewController new];
        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
        
    }else if (indexPath.row == 2){
        HomeGoodsListViewController * vc = [HomeGoodsListViewController new];
//        HomeTransferOrderInfoViewController * vc = [HomeTransferOrderInfoViewController new];

        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    }else{
        ZJMineThroughRecordViewController * vc = [ZJMineThroughRecordViewController new];
        vc.hidesBottomBarWhenPushed = false;
        [[SaViewControllerUtils currentViewController].navigationController pushViewController:vc animated:YES];
    }
}




#pragma mark - item宽高
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(SCREEN_WIDTH / 2, ALIGN_HEIGHT_PT(90));
}

#pragma mark - <UICollectionViewDelegateFlowLayout>
#pragma mark - X间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return  ALIGN_WIDTH_PT(0);
}
#pragma mark - Y间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return  ALIGN_WIDTH_PT(0);
}






#pragma mark -- 懒加载
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor clearColor];
        [_collectionView registerClass:[HomeHeaderCareCollectionViewCell class] forCellWithReuseIdentifier:@"HomeHeaderCareCollectionViewCell"];
        
//        self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//            self->pageNum = 1;
//            [self loadNet];
//        }];
//
//        self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
//            self->pageNum += 1;
//            [self loadNet];
//        }];
        
        
    }
    return _collectionView;
}




@end
